package com.credit.core.enumtype;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSON;

/**    
 *     
 * 项目名称：core    
 * 类名称：ReturnCodeEnum    
 * 类描述：  系统返回状态码  
 * 创建人：huan    
 * 创建时间：2016年3月16日 下午2:01:33    
 * 修改人：huan    
 * 修改时间：2016年3月16日 下午2:01:33    
 * 修改备注：    
 * @version     
 *     
 */
public enum ReturnCodeEnum {
	
	C200_							("200","SUCESS!"),
	C202_ACCOUNT_SERVER_ERROR		("202","帐号服务器查询失败，请过一段时间重试"),
	C202_CANNOT_CREATE_APP_FOLDER	("202","不能创建用户目录，请重新获取ACCESS TOKEN"),
	C202_LOGIN_FAIL					("202","登陆失败，可能用户密码不对或者无此帐号"),
	C202_WRONG_VERIFICATION_CODE	("202","注册验证码错误或者失效"),
	C202_COMMIT_FAIL				("202","上传失败，请过一段时间重试"),
	C202_BAD_OPENID					("202","不能用此OPENID 注册"),
	C400_BAD_PARAMETERS				("400","参数不正确"),
	C400_BAD_REQUEST				("400","请求URL、参数不对"),
	C400_NO_SUCH_API_IMPLEMENTED	("400","无此API"),
	C401_BAD_SIGNATURE				("401","签名不正确"),
	C401_REQUEST_EXPIRED			("401","请求过期（TIMESTAMP 或者NONCE不正确）"),
	C401_BAD_CONSUMER_KEY			("401","没有这个CONSUMER KEY （你确定申请了应用？）"),
	C401_NOT_SUPPORTED_AUTH_MODE	("401","你不能使用这种授权模式"),
	C401_AUTHORIZATION_EXPIRED		("401","用户的授权过期，请重新获取ACCESS_TOKEN"),
	C401_API_DAILY_LIMIT			("401","您今天调用接口次数太多了吧"),
	C401_NO_RIGHT_TO_CALL_THIS_API	("401","无权限调用此API"),
	C401_REUSED_NONCE				("401","NONCE被重用了"),
	C401_BAD_VERIFIER				("401","VERIFIER错误"),
	C403_FILE_EXIST					("403","同名文件（夹）已经存在"),
	C403_FORBIDDEN					("403","无权限访问，或者无权限进行此操作"),
	C404_FILE_NOT_EXIST				("404","文件夹不存在，父目录不存在"),
	C404_MSG_NOT_FOUND				("404","查无此数据"),
	C406_TOO_MANY_FILES				("406","一次操作太多文件"),
	C413_FILE_TOO_LARGE				("413","文件大小超过能上传的上限"),
	C500_SERVER_ERROR				("500","服务器错误，应该是我们遇到BUG了"),
	C507_OVER_SPACE					("507","用户空间已满");
	
	private String code;
	private String message;
	private String date;


	public String getDate() {
		return System.currentTimeMillis()/1000+"";
	}

	public void setDate(String date) {
		this.date = date;
	}
	
	
	private ReturnCodeEnum ( String code , String message ){
		this.code = code;
		this.message = message;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public static ReturnCodeEnum getEnumByName(String status) {
		ReturnCodeEnum[] enums = ReturnCodeEnum.values();
		for(ReturnCodeEnum enumtype:enums) {
			if(enumtype.getCode().equals(status)) {
				return enumtype;
			}
		}
		return C400_BAD_REQUEST;
	}
	
	/*public String setParam(Map<String , Object> map){
		if(!MapUtils.isEmpty(map)){
			Map<String ,Object> result = new HashMap<>();
			result.put("data", map);
			result.putAll(toSimpleMap());
			return JSON.toJSONString(result);
		}else{
			return null;
		}
	}
	
	public String setParam(Record record){
		if(null!=record){
			Map<String ,Object> result = new HashMap<>();
			result.put("data", record.getColumns());
			result.putAll(toSimpleMap());
			return JSON.toJSONString(result);
		}else{
			return null;
		}
	}
	
	public String setParam(List<Record> list){
		Map<String , Object >  map = new HashMap<>();
		if(!CollectionUtils.isEmpty(list)){
			List<Map<String , Object>> paramList = new ArrayList<>();
			for(Record record:list){
				Map<String , Object> mapTemp = record.getColumns();
				paramList.add(mapTemp);
			}
			map.putAll(toSimpleMap());
			map.put("data", paramList);
			return JSON.toJSONString(map);
		}else{
			return null;
		}
	}*/

	public String toSimpleString() {
		Map<String , Object> map = new HashMap<>();
		map.put("code", code);
		map.put("message", message);
		map.put("date", date);
 		return JSON.toJSONString(map) ;
	}
	
	public Map<String , Object> toSimpleMap() {
		Map<String , Object> map = new HashMap<>();
		map.put("code", code);
		map.put("message", message);
		map.put("date", getDate());
 		return map ;
	}
	
	public static void main(String[] args) {
		System.out.println(ReturnCodeEnum.C200_.toSimpleString());
	}
	
}
